/**
 * Created by user on 2017/9/22.
 */
import Storage from '../storage';
import { LOGIN } from '../actions/ActionTypes';
const init_state = {
    loading:false,
    user:Storage.read('login_user')
};

const login = ( state=init_state,action )=>{
    switch(action.type){
        case LOGIN.LOADING:
            return Object.assign({},init_state,{loading:action.payload});
        case LOGIN.LOGIN_SUCCESS:
            return Object.assign({},init_state,{user:action.payload});
        case LOGIN.LOGOUT_SUCCESS:
            return Object.assign({},init_state,{user:null});
        default:
            return state;
    }
};
export default login;